


import java.io.IOException;
import java.util.ArrayList;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import view.DestinoDTO;
import view.HotelDTO;
import controller.Sistema;


public class Hoteles extends HttpServlet{

	private static final long serialVersionUID = 1L;

	
	public void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		System.out.println("get a hoteles");
		this.doPost(req, resp);
	}

	
	public void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		System.out.println("post a hoteles");
		String action = req.getParameter("action");
		String msg="";
		String msgErr="";			        
		int idHotel=0;
    	String nombreHotel="";
    	int categoria=0;
    	int estado=2;
    	
        ArrayList<DestinoDTO> destinos = Sistema.getInstancia().buscarDestinos();
        req.getSession().setAttribute("destinos", destinos);
    	
    	if (req.getParameter("idHotel")!=null && req.getParameter("idHotel").length()>0)
    	{
    		idHotel=Integer.valueOf(req.getParameter("idHotel"));
    	}
    	if (req.getParameter("nombre")!=null)
    	{
    		nombreHotel=req.getParameter("nombre").trim();
    	}
    	if (req.getParameter("categoria")!=null && req.getParameter("categoria").length()>0)
    	{
    		categoria=Integer.valueOf(req.getParameter("categoria"));
    	}
    	if (req.getParameter("estado")!=null && req.getParameter("estado").length()>0)
    	{
    		estado=Integer.valueOf(req.getParameter("estado"));
    	}
    	System.out.println("getHoteles");
    	ArrayList<HotelDTO> hoteles = Sistema.getInstancia().buscarHotel(nombreHotel
    															, idHotel
    															, estado
    															, categoria);
    	req.getSession().setAttribute("listado", hoteles);
    	
    	if (hoteles.size() == 0)
    	{
    		req.setAttribute("msgErr", "No se han encontrado registros");
    	}
		RequestDispatcher dispatcher = req.getRequestDispatcher("hoteles.jsp");
		dispatcher.forward(req, resp);	
	 }
    protected void dispatch(String page, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
    {
        if (page != null)
        {
            RequestDispatcher rd = request.getRequestDispatcher(page);
            rd.forward(request, response);
        }
    }
}
